package com.tanhua.server.controller;

import com.tanhua.model.domain.PageResult;
import com.tanhua.model.domain.vo.SettingsVo;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author lk
 * @date 2022-03-25
 */
@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /**
     * 查询通用设置
     */
    @GetMapping("/settings")
    public ResponseEntity settings(){
        //获取当前用户id
        SettingsVo settings = settingsService.settings();
        return ResponseEntity.ok(settings);
    }

    /**
     * 设置陌生人问题
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map){
        //获取陌生人问题
        String content = (String) map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok(null);
    }

    /**
     * 通知设置
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map){
        //获取设置的参数
        settingsService.saveSettings(map);
        return ResponseEntity.ok(null);
    }

    //黑名单分页查询
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int size){
        //调用service查询
        PageResult pageResult = settingsService.blacklist(page,size);
        return ResponseEntity.ok(pageResult);
    }

    //取消黑名单
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long blackUserId){
        settingsService.deleteBlackList(blackUserId);
        return ResponseEntity.ok(null);

    }

}
